#pragma once
#ifndef __GLF_DEBUGGER_PERF_COUNTERS_H__
#define __GLF_DEBUGGER_PERF_COUNTERS_H__

#include <glf/config.h>

#if GLF_ENABLE_DEBUGGER

#include <glf/debugger/debugger.h>
#include <vector>

namespace glf
{
namespace debugger
{

class PerfCounters : public Module
{
	GLF_DECLARE_SINGLETON_WITH_DEP(PerfCounters, Debugger)
public:
	struct Counter
	{
		static const uint BUFFER_SIZE = 30;
		uint mValues[BUFFER_SIZE];
	};

	typedef std::map<stringdbg, Counter, std::less<stringdbg>, DebuggerAllocator<std::pair<const stringdbg, Counter> > > CounterMap;

	static void UpdateValue(const char* name, uint value)
	{
		PerfCounters* perfInst = PerfCounters::GetInstance();
		perfInst->mCounters[name].mValues[perfInst->mPosition] = value;
	}

	virtual ~PerfCounters();
	virtual void UpdateFrame();
	virtual void Parse(int type, PacketReader& in);

	static const CounterMap& GetCounters()
	{
		return PerfCounters::GetInstance()->mCounters;
	}

private:
	PerfCounters();
	
	enum MessageType
	{
		// Debugger to Glf
		MESSAGE_SET_ENABLED,

		// Glf to Debugger
		MESSAGE_COUNTERS
	};

	void SendPerformanceCounters();

	
	CounterMap mCounters;
	bool mEnabled;
	uint mPosition;
};

} // end namespace debugger
} // end namespace glf

#endif // GLF_ENABLE_DEBUGGER

#endif // __GLF_DEBUGGER_PERF_COUNTERS_H__
